package com.chcplayer.skin
{
import com.chcplayer.enums.UISize;
import com.chcplayer.interfaces.ISkinPic;
import com.chcplayer.interfaces.ITextOwner;

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

/**
 * author yh
 */
public class BaseButtonSkinState extends Sprite implements ITextOwner, ISkinPic
{
	/**
	 */
	protected var p_ttf:TextField = new TextField();
	/**
	 */
	protected var p_strText:String = "";
	/**
	 */
	protected var p_nW:int;
	protected var p_nH:int;
	/**
	 */
	public function BaseButtonSkinState()
	{
		super();
		p_ttf.autoSize = TextFieldAutoSize.LEFT;
		this.addChild(p_ttf);
	}
//--------------------------------------------------------------------------------------------------
// private
//--------------------------------------------------------------------------------------------------
	protected function _Resize():void
	{
		this.graphics.clear();
		this.graphics.beginFill(0,0);
		this.graphics.drawRect(0, 0, p_nW, p_nH);
		p_ttf.text = p_strText;
		p_ttf.x = (p_nW - p_ttf.width) >> 1;
		p_ttf.y = (p_nH - p_ttf.height) >> 1;
	}
//==================================================================================================
// public
//==================================================================================================
	/**
	 */
	public function getDefaultWidth():int
	{
		return 80;
	}
	/**
	 */
	public function getDefaultHeight():int
	{
		return UISize.BUTTON_H;
	}
	/**
	 */
	public function setText(strT:String):void
	{
		p_strText = strT;
		this._Resize();
	}
	
	public function getText():String
	{
		return p_strText;
	}
	/**
	 */
	public function setSizeWH(nW:int, nH:int):void
	{
		p_nW = nW;
		p_nH = nH;
		this._Resize();
	}
}
}